package com.course.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.course.delegate.UserMgrDelegate;
import com.course.exception.ConnectionException;
import com.course.exception.DataNotFoundException;
import com.course.util.CoreList;
import com.course.util.UtilConstants;



public class ViewStudentsAction extends HttpServlet {

	
	private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
                doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path="";
		CoreList studentInfo=null;

		  try{
			  
			 
			    String path1=request.getRealPath("/userimages");
			  
			 
			  try{
		       studentInfo= new UserMgrDelegate().getStudents(path1);				  								 
			  }catch (DataNotFoundException  e) {
				e.printStackTrace();
			}catch (ConnectionException e) {
				e.printStackTrace();
			}
			  
			  System.out.println("in Action class vcb Feedback..........."+studentInfo);
			  
			  
			  if(!studentInfo.isEmpty()){
				  request.setAttribute("FacultyInfo", studentInfo);
				  request.setAttribute("status", UtilConstants._STUDENT_INFO);
				  path=UtilConstants._VIEW_STUDENT;
				 }
			  else {
				  request.setAttribute("status", UtilConstants._NO_STUDENT_INFO);
				  path=UtilConstants._VIEW_STUDENT;
				}
			  }
		  catch (NullPointerException e) {
			  request.setAttribute("status", UtilConstants._INVALIED_DATA);
			  path=UtilConstants._VIEW_STUDENT;
			e.printStackTrace();
			path="./jsps/ViewStudents.jsp?status=Invalid Entries";
		}
		 RequestDispatcher rd=request.getRequestDispatcher(path);
			rd.forward(request,response);

		
	}

}
